package com.hbk.member.controller;

import com.hbk.commom.utils.R;
import com.hbk.member.entity.BlAdmin;
import com.hbk.member.entity.vo.LoginParamVO;
import com.hbk.member.service.BlAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@RestController
@RequestMapping("/user")
@CrossOrigin
public class LoginController {
    @Autowired
    BlAdminService adminService;
    @PostMapping("login")
    public R loginVO(@RequestBody LoginParamVO vo){
        String token = adminService.login(vo);
        return token == null ? R.error() : R.ok().data("token",token);
    }
    @GetMapping("info")
    public R getInfo(@RequestParam("token") String token){
        BlAdmin userInfo = adminService.getInfo(token);
        if(userInfo != null){
            return R.ok().data("roles","帅哥管理员")
                    .data("avatar",userInfo.getHeader())
                    .data("name",userInfo.getUsername());
        }else{ return R.error();}

    }

}
